spotifyr facilitates pulling album and track data based on search criteria. [Charlie Thompson @_RCharlie](“http://www.twitter.com/@_RCharlie”) has a great tutorial, which I used to create this analysis.
We’ll be using the tidyverse, of course, spotifyr, rpart, dendextend and circlize. Swiped code appears in the comments
library(spotifyr)#http://www.rcharlie.com/spotifyr/
library(tidyverse)
library(rpart)
library(dendextend)
library(circlize) #https://stats.stackexchange.com/questions/4062/how-to-plot-a-fan-polar-dendrogram-in-r
library(plotly)
if(!grepl("misc", getwd())){setwd("./misc")}
There is more than one David Bowie (no, no there isn’t) so we need to indicate which one we want.
I’m going to save that as RDS so that I don’t have to manually intervene each time I run this script
The first exploration I’m going to do is for the overall sentiment of each track in the database. I’m going to emulate Charlie Thompson’s really cool sentify app which looks at valence - a measure of a track’s “positivity”, and its energy. This produces 4 quadrants from Sad/Depressing (low energy, low valence) to Happy/Joyful (high energy, high valence). I’m producing these with plotly so you can hover for details
p<-ggplot(bowie) +
geom_point(aes(x=valence, y=energy, color=track_name),show.legend = FALSE)+
geom_hline(aes(yintercept=0.5))+
geom_vline(aes(xintercept=0.5))+
annotate("text", x=1, y=1, label="Happy/Joyful", hjust=1)+
annotate("text", x=1, y=0, label="Chill/Relaxing", hjust=1)+
annotate("text", x=0, y=0, label="Sad/Depressing", hjust=0)+
annotate("text", x=0, y=1, label="Turbulent/Dark", hjust=0)
ggplotly(p) %>%
layout(showlegend = FALSE)